{% block component_product_box_price_info %}
    {% set cheapest = product.calculatedCheapestPrice %}

    {% set real = product.calculatedPrice %}
    {% if product.calculatedPrices.count > 0 %}
        {% set real = product.calculatedPrices.last %}
    {% endif %}

    {% set referencePrice = real.referencePrice %}

    {% set displayFrom = product.calculatedPrices.count > 1 %}
    {% set displayParent = product.variantListingConfig.displayParent and product.parentId === null %}

    {% if displayParent %}
        {% set displayFromVariants = displayParent and real.unitPrice !== cheapest.unitPrice %}
        {% set real = cheapest %}
        {% set totalVariants = product.cheapestPriceContainer.value %}
        {% set hasDifferentPrice = totalVariants|filter(variant => variant.default != null)|length > 0 %}
    {% endif %}

    <div class="product-price-info">
        {% block component_product_box_price_unit %}
            <p class="product-price-unit">
                {# Price is based on the purchase unit #}
                {% block component_product_box_price_purchase_unit %}
                    {% if referencePrice and referencePrice.unitName %}
                        <span class="product-unit-label">
                            {{ 'listing.boxUnitLabel'|trans|sw_sanitize }}
                        </span>
                        <span class="price-unit-content">
                            {{ referencePrice.purchaseUnit }} {{ referencePrice.unitName }}
                        </span>
                    {% endif %}
                {% endblock %}

                {# Item price is based on a reference unit #}
                {% block component_product_box_price_reference_unit %}
                    {% if referencePrice is not null %}
                        <span class="price-unit-reference">
                            ({{ referencePrice.price|currency }} / {{ referencePrice.referenceUnit }} {{ referencePrice.unitName }})
                        </span>
                    {% endif %}
                {% endblock %}
            </p>
        {% endblock %}

        {% block component_product_box_price %}
            <div class="product-price-wrapper">
                {% set price = real %}
                {% set isListPrice = price.listPrice.percentage > 0 %}
                {% set isRegulationPrice = price.regulationPrice != null %}

                {#
                    Cheapest price display for variants. Used when the product is a single variant that is directly buy-able from the listing.
                    Example: "Variants from $120.00"
                #}
                <div class="product-cheapest-price{% if isListPrice and isRegulationPrice and not displayFrom and not displayFromVariants %} with-list-price{% endif %}{% if isRegulationPrice and not displayFrom and displayFromVariants %} with-regulation-price{% endif %}{% if displayFrom and isRegulationPrice %} with-from-price{% endif %}">
                    {% if cheapest.unitPrice != real.unitPrice and cheapest.variantId != product.id %}
                        {{ 'listing.cheapestPriceLabel'|trans|sw_sanitize }}<span class="product-cheapest-price-price"> {{ cheapest.unitPrice|currency }}</span>
                    {% endif %}
                </div>

                {#
                    Price label for screen readers.
                    Example with regular price: "Regular price:"
                    Example with list price: "Sale price:"
                #}
                <span class="visually-hidden product-price-label">
                    {% if isListPrice and not displayFrom and not displayFromVariants %}
                        {{ 'listing.listPriceLabel'|trans|sw_sanitize }}
                    {% else %}
                        {{ 'listing.regularPriceLabel'|trans|sw_sanitize }}
                    {% endif %}
                </span>

                {#
                    "From" price display. Used for advanced pricing tables or variants when the storefront presentation is set to "main variant".
                    The product is not directly buy-able from the listing.
                    Example: "From $120.00"
                #}
                {% if displayFrom or (displayParent and hasDifferentPrice and totalVariants|length > 1) %}
                    {{ 'listing.listingTextFrom'|trans|sw_sanitize }}
                {% endif %}

                {#
                    Main price display. Always used, can also include list prices.
                    Example: $150.00"
                    Example with list price: €400.00 <s>€500.00</s> (20% saved)"
                #}
                <span class="product-price{% if isListPrice and not displayFrom and not displayFromVariants %} with-list-price{% endif %}">
                    {{ price.unitPrice|currency }}

                    {% if isListPrice and not displayFrom and not displayFromVariants %}
                        {% set afterListPriceSnippetExists = 'listing.afterListPrice'|trans|length > 0 %}
                        {% set beforeListPriceSnippetExists = 'listing.beforeListPrice'|trans|length > 0 %}
                        {% set hideStrikeTrough = beforeListPriceSnippetExists or afterListPriceSnippetExists %}

                        <span class="list-price{% if hideStrikeTrough %} list-price-no-line-through{% endif %}">
                            {% if beforeListPriceSnippetExists %}{{ 'listing.beforeListPrice'|trans|trim|sw_sanitize }}{% endif %}

                            <span class="visually-hidden list-price-label">{{ 'listing.regularPriceLabel'|trans|sw_sanitize }}</span>

                            <span class="list-price-price">{{ price.listPrice.price|currency }}</span>

                            {% if afterListPriceSnippetExists %}{{ 'listing.afterListPrice'|trans|trim|sw_sanitize }}{% endif %}

                            <span class="list-price-percentage">{{ 'detail.listPricePercentage'|trans({'%price%': price.listPrice.percentage })|sw_sanitize }}</span>
                        </span>
                    {% endif %}
                </span>

                {#
                    Display for previous price
                    Example: "previously €300.00"
                #}
                {% if isRegulationPrice %}
                    <span class="product-price with-regulation-price">
                        {% if isListPrice %}<br aria-hidden="true">{% endif %}<span class="regulation-price">{{ 'general.listPricePreviously'|trans({'%price%': price.regulationPrice.price|currency }) }}</span>
                    </span>
                {% endif %}
            </div>
        {% endblock %}

        {#
            If a product can be added to the shipping directly from the listing,
            we need to display information about taxes and shipping.
        #}
        {% if config('core.listing.allowBuyInListing') %}
            {% block component_product_box_price_tax_info %}
                {% set cmsPath = 'frontend.cms.page' %}

                <button class="product-price-tax-link btn btn-link-inline fs-6"
                        type="button"
                        data-ajax-modal="true"
                        data-url="{{ path(cmsPath, { id: config('core.basicInformation.shippingPaymentInfoPage') }) }}">
                    {% if context.taxState == 'gross' %}
                        {{ 'general.grossTaxInformation'|trans|sw_sanitize }}
                    {% else %}
                        {{ 'general.netTaxInformation'|trans|sw_sanitize }}
                    {% endif %}
                </button>
            {% endblock %}
        {% endif %}
    </div>
{% endblock %}
